//
//  CDSearcherController.m
//  CuriosityDaily3
//
//  Created by 安林 on 16/9/25.
//  Copyright © 2016年 theBestTeam. All rights reserved.
//

#import "CDSearcherController.h"
#import "CDMoreViewController.h"

@interface CDSearcherController ()

@end

@implementation CDSearcherController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.view.backgroundColor = [UIColor whiteColor];
}

-(void)setupUI{
    UISearchBar *searchBar = [[UISearchBar alloc]init];
    searchBar.frame = CGRectMake(0, 0, self.view.bounds.size.width, 64);
    searchBar.placeholder = @"搜索";
    [searchBar setShowsCancelButton:NO];//显示右侧取消按钮
    
    [searchBar setBackgroundColor:[UIColor blackColor]];
    //2.关键
    [[[searchBar.subviews objectAtIndex:0].subviews objectAtIndex:0] removeFromSuperview];
    
    
    //显示取消按钮
    searchBar.showsCancelButton=YES;
    
    UIButton *cancelBtn=[searchBar valueForKey:@"_cancelButton"];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(cancelClick) forControlEvents:UIControlEventTouchUpInside];
    cancelBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    //设置光标的颜色
    searchBar.tintColor=[UIColor orangeColor];
    
    
    UITextField *searchFiled=[searchBar valueForKey:@"_searchField"];
    //设置处于编辑状态
    [searchFiled becomeFirstResponder];
    
    //输入文本的颜色
    searchFiled.textColor=[UIColor blackColor];
    
    //输入文本字体的大小
    searchFiled.font=[UIFont systemFontOfSize:14];
    
    //输入框的圆角设置
    searchFiled.layer.cornerRadius=10;
    searchFiled.layer.masksToBounds=YES;
    
    //输入框里面的背景颜色
    searchFiled.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:searchBar];
    
}
-(void)cancelClick{
    [self dismissViewControllerAnimated:NO completion:nil];
    [self.view endEditing:YES];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"cancelClick" object:nil];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

@end
